
'use strict'

const Sequelize = require('sequelize')
const mysql2 = require('mysql2')
const Op = Sequelize.Op

const DBPool = new Sequelize(process.env.MYSQL_DATABASE_APP, process.env.MYSQL_USER, process.env.MYSQL_PASSWORD, {
  host: process.env.MYSQL_HOST,
  port: process.env.MYSQL_PORT,
  dialect: 'mysql',
  dialectModule: mysql2,
  pool: {
    max: 10,
    min: 5,
    idle: 28800
  },
  timezone: '+08:00'
})

const DBPoolUser = new Sequelize(process.env.MYSQL_DATABASE_USER, process.env.MYSQL_USER, process.env.MYSQL_PASSWORD, {
  host: process.env.MYSQL_HOST,
  port: process.env.MYSQL_PORT,
  dialect: 'mysql',
  dialectModule: mysql2,
  pool: {
    max: 10,
    min: 5,
    idle: 28800
  },
  timezone: '+08:00'
})

const DBPoolFile = new Sequelize(process.env.MYSQL_DATABASE_FILE, process.env.MYSQL_USER, process.env.MYSQL_PASSWORD, {
  host: process.env.MYSQL_HOST,
  port: process.env.MYSQL_PORT,
  dialect: 'mysql',
  dialectModule: mysql2,
  pool: {
    max: 10,
    min: 5,
    idle: 28800
  },
  timezone: '+08:00'
})

const DBPoolProduction = new Sequelize(process.env.MYSQL_DATABASE_PRODUCTION, process.env.MYSQL_USER, process.env.MYSQL_PASSWORD, {
  host: process.env.MYSQL_HOST,
  port: process.env.MYSQL_PORT,
  dialect: 'mysql',
  dialectModule: mysql2,
  pool: {
    max: 10,
    min: 5,
    idle: 28800
  },
  timezone: '+08:00'
})

const DBPoolSquare = new Sequelize(process.env.MYSQL_DATABASE_SQUARE, process.env.MYSQL_USER, process.env.MYSQL_PASSWORD, {
  host: process.env.MYSQL_HOST,
  port: process.env.MYSQL_PORT,
  dialect: 'mysql',
  dialectModule: mysql2,
  pool: {
    max: 10,
    min: 5,
    idle: 28800
  },
  timezone: '+08:00'
})

module.exports = {
  Sequelize,
  Op,
  DBPool,
  DBPoolUser,
  DBPoolFile,
  DBPoolProduction,
  DBPoolSquare
}
